package com.mogist.hqc.module.order.presenter

import com.mogist.hqc.entitys.BaseResponse
import com.mogist.hqc.entitys.response.OrderVo
import com.mogist.hqc.module.order.contract.OrderDetailContract
import com.mogist.hqc.mvp.HttpDto
import com.mogist.hqc.mvp._PresenterImpl
import com.mogist.hqc.util.Constant
import talex.zsw.basecore.util.JsonTool
import talex.zsw.basecore.view.dialog.sweetalertdialog.SweetAlertDialog

/**
 * 作用：订单详情
 * 作者：赵小白 email:vvtale@gmail.com  
 * 修改人：
 * 修改时间：
 * 修改备注：
 */
class OrderDetailPresenter(view: OrderDetailContract.View) : _PresenterImpl<OrderDetailContract.View, BaseResponse>(
        view), OrderDetailContract.Presenter
{
    override fun requestSuccess(response: BaseResponse, http: HttpDto)
    {
        when (http.url)
        {
            Constant.ORDER_DETAIL ->
            {
                if (response.success)
                {
                    mView.disDialog()
                    val vo = JsonTool.getObject(response.content, OrderVo::class.java)
                    mView.bindDetail(vo)
                }
                else
                {
                    mView.showDialog(SweetAlertDialog.ERROR_TYPE,
                                     "获取订单列表失败",
                                     response.message,
                                     "确定",
                                     null,
                                     mView.finishListener,
                                     null)
                }
            }
            Constant.ORDER_CANCEL ->
            {
                if (response.success)
                {
                    mView.cancelSuccess()
                }
                else
                {
                    mView.showDialog(SweetAlertDialog.ERROR_TYPE, "取消订单失败", response.message)
                }
            }
            Constant.ORDER_COMMENT ->
            {
                if (response.success)
                {
                    mView.disDialog()
                    mView.commentSuccess()
                }
                else
                {
                    mView.showDialog(SweetAlertDialog.ERROR_TYPE, "发表评论失败", response.message)
                }
            }
        }
    }
}